<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.ArrayList, java.util.Iterator" %>
<%@ page import="util.Helper,pojo.ItemAttr,pojo.UserAttr" %>
<%
    Object validTime       = session.getAttribute("validTime");
    long nowTimeStamp      = Helper.getTimeStamp();
    if(validTime == null || Long.parseLong(validTime.toString()) < nowTimeStamp) {
        request.setAttribute("errorInfo", "非法登陆！");
        request.getRequestDispatcher("hint.jsp").forward(request, response);
    }
    Object objUserAttr   = session.getAttribute("userAttr");
    if(objUserAttr == null) {
        request.setAttribute("errorInfo", "非法登陆！");
        request.getRequestDispatcher("hint.jsp").forward(request, response);
    }
    Boolean isPoll       = (Boolean)session.getAttribute("isPoll");
    UserAttr userAttr   = (UserAttr)objUserAttr;
    int userId          = userAttr.getUserId();
    int userType        = userAttr.getUserType();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>进行投票</title>
<link rel="stylesheet" href="css/base.css" />
<style type="text/css">
    .content {
        text-align: center;
    }
    .poll_items ul li{
        clear: both;
        width: 200px;
        margin: 0px auto;
        list-style-type: none;
    }
    
</style>
</head>
<body>
    <div class="wrap">
        <div class="header">
            <p class="tool_bar">
                <a href="javascript:location.reload();">[刷新]</a>
                <a href="javascript:history.go(-1);">&lt;&lt;返回上一页</a>
                <a href="./index">返回主页&gt;&gt;</a>
                <% if (userType == 1){ %><a href="./admin">[进入管理]</a> <%} %>
                <a href="./logout">[退出]</a>
            </p>
            <h1>您的选择？</h1>
        </div>
        <div class="content">
            <div class="poll_items">
                <%
                   Object obj   = request.getAttribute("items");
                   if(obj == null) {
                       out.print("投票还没开放！");
                   } else {
                 %>
                 <form action="./poll" method="POST" name="poll_form">
                 <table cellspacing="1" cellpadding="1" border="1" width="500" align="center"> 
                 <%
                       ArrayList<ItemAttr> items  = (ArrayList<ItemAttr>)obj;
                       Iterator<ItemAttr> iItems  = items.iterator();
                       while(iItems.hasNext()) {
                           ItemAttr item    = (ItemAttr)iItems.next();
                           String itemName  = item.getItemName();
                           int itemId       = item.getItemId();
                           if(isPoll == false) {
                %>
                <tr>
                    <td style="text-align: right" width="50%"><%=itemName %></td>
                    <td><input type="radio" value="<%=itemId%>" name="item_id"/></td>
                <%} else { %>
                    <td style="text-align: center" colspan="2"><%=itemName %></td>
                <%} %>
                </tr>
                <% } %>
                </table>
                <p>
                <%if(isPoll == false) { %>
                    <input type="submit" value="提交选择"/>
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="reset" value="重新选择"/>
                <%} else {%>
                                       欢迎回来，您已经投过票了！
                <%} %>
                </p>
                
                <input type="hidden" name="user_id" value="<%=userId%>" />
                </form>
                <% 
                   }
                %>
            </div>
        </div>
        <jsp:include page="./comm/footer.jsp" flush="true"/>
    </div>
</body>
</html>